//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    id1: "奖金",
    id2: "红包",
    id3: "工资",
    id4: "兼职",
    id5: "办公",
    id6: "交通",
    id7: "娱乐",
    id8: "学习",
    id9: "餐饮",
    id10: "服饰",
    id11: "网购",
    id12: "日用",
    id13: "住房",
    id14: "社交",
    id15: "通讯",
    id16: "其他",
    types: 'cost',
    money: 0.00,
    screenclass: "其他",
    tip: '',
    t1:''
  },

  //实现类型跳到类型框
  ClickButton: function (event) {
    this.setData({
      screenclass: event.target.id
    })
    this.screenclass = event.target.id
   
  },

//选择收入还是支出
  radioChange: function (e) {
    this.setData({
      types: e.detail.value
    })
    this.types = e.detail.value
  },
//输入金额
  inputmoney: function (e) {
    this.data.money = e.detail.value
  },
//输入备注
  inputip: function (e) {
    this.data.tip = e.detail.value
  },
//判断金额不能为空且将数据传入数据库
  commitaccount: function () {
    if (this.data.money == 0) {
      wx.showModal({
        title: '提示',
        content: '金额不能为空！',
      })
    } else {
      if (this.data.types == 'cost') {
        this.data.money = -1 * this.data.money
      }
      wx.request({
        url: 'https://hi.slickghost.com/WebTest/Operate',
        data: {
          openid: app.globalData.openid,
          tname: this.data.screenclass,
          tip: this.data.tip,
          money: this.data.money,
          choice: 'insertaccount'
        },
        header: {
          'content-type': 'json'
        },
        success: function (res) {
          wx.showToast({
            title: '记录成功！',
            icon: 'success',
            duration: 2000
          })
        }
      })
    }
  }
})
